﻿using System;

namespace _4_Toeplitz
{
    class Program
    {
        static int read()
        {
            bool isOK = false; int res = 0;
            while (isOK == false)
            {
                try
                {
                    res = int.Parse(Console.ReadLine());
                    isOK = true;
                }
                catch
                {
                    Console.WriteLine("请重新输入此行");
                }
            }
            return res;
        }
        static int[] ReadaLine(int m, int n)
        {
            int[] tem = new int [n];
            string Line = Console.ReadLine();
            int length = Line.Length, i = 0;
            for (int j = 0; j < n; j++)
            {
                while (!(Line[i] >= '0' && Line[i] <= '9')) i++;
                int res = (int) Line[i] - (int)'0'; i++;
                while (i < length && Line[i] >= '0' && Line[i] <= '9')
                {
                    res = res * 10 + (int)Line[i] - (int)'0';
                    i++;
                }
                tem[j] = res;
            }
            return tem;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("请分两行输入矩阵的行数和列数：");
            int m, n;
            m = read(); n = read();
            int[][] arr = new int[m][];
            Console.WriteLine("请按矩阵格式输入矩阵");
            for (int i = 0; i < m; i++)
                arr[i] = ReadaLine(m, n);
            int M = m - 1;
            for (int N = 0; N < n; N++)
            {
                int nowM = M, nowN = N, isOK = 1;
                int theNumber = arr[M][N];
                for (; nowM >= 0 && nowM < m && nowN >= 0 && nowN < n && isOK == 1; )
                {
                    if (arr[nowM][nowN] != theNumber) isOK = 0;
                    nowM--; nowN--;
                }
                if (isOK != 1)
                {
                    Console.WriteLine("不是托普利茨矩阵");
                    return;
                }
            }
            M = 0;
            for (int N = 1; N < n; N++)
            {
                int nowM = M, nowN = N, isOK = 1;
                int theNumber = arr[M][N];
                for (; nowM >= 0 && nowM < m && nowN >= 0 && nowN < n && isOK == 1;)
                {
                    if (arr[nowM][nowN] != theNumber) isOK = 0;
                    nowM++; nowN++;
                }
                if (isOK != 1)
                {
                    Console.WriteLine("不是托普利茨矩阵");
                    return;
                }
            }
            Console.WriteLine("是托普利茨矩阵");
            return;
        }
    }
}
